<template>
	<view class="entry-main">
		<u-loading-page :loading="loading" loading-text="加载中..." loading-mode="spinner"></u-loading-page>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading: true,
				timer: undefined,
			};
		},
		onLoad() {},

		async onShow() {
			this.timer = setTimeout(() => {
				uni.switchTab({
					url: "/pages/Home/index",
				});
			}, 3 * 1000);
			this.$util.checkPage().then(res => {
				const isOpenPage = res
				let app = getApp();
				const tokenResult = uni.getStorageSync("access_token");
				//判断是否登录
				if (tokenResult) {
					clearTimeout(this.timer);
					//0求职者，1招聘者
					if (app.globalData.userRole === 0) {
						//判断是否第一次进入下载的软件
						const chuci = uni.getStorageSync("chuci");
						if (chuci) {
							uni.switchTab({
								url: "/pages/Home/index",
							});
						} else {
							uni.setStorageSync("chuci", 1);
							//判断用户信息是否存在
							if (app.globalData.userResume == null) {
								uni.navigateTo({
									url: "/pages/views/packageB/userMessage/index",
								});
							} else {
								uni.switchTab({
									url: "/pages/Home/index",
								});
							}
						}
					} else if (app.globalData.userRole === 1) {
						// 判断招聘者的信息是否填了，填了可以进入
						if (app.globalData.corps.length == 0) {} else {
							clearTimeout(this.timer);
							uni.switchTab({
								url: "/pages/Home/index",
							});
						}
					}
				} else if (!isOpenPage) {
					clearTimeout(this.timer);
					uni.reLaunch({
						url: "/pages/Login/login",
					});
					return;
				}
			})

			// //没有特殊情况都跳转到首页
		},
		onHide() {
			if (this.timer) {
				clearTimeout(this.timer);
				this.timer = undefined;
				console.log("------ onHide 取消 超时跳转首页");
			}
		},
		onUnload() {
			if (this.timer) {
				clearTimeout(this.timer);
				this.timer = undefined;
				console.log("------ onUnload 取消 超时跳转首页");
			}
		},
		methods: {},
	};
</script>

<style lang="scss" scoped>
	.entry-main {
		height: 100vh;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>